import { get_products_list } from "@/api";

const publicStore = {
    state: {
        product_infos: [],
    },
    mutations: {
        'SET_PRODUCTS': (state, product_infos) => {
            state.product_infos = product_infos;
        },
    },
    actions: {
        'GET_PRODUCTS': ({ commit }, page_info = { page: 1, page_size: 300 }) => { //获取产品列表
            return new Promise((resolve) => {
                // if(state.product_info.length) {
                //     resolve(state.product_info)
                //     return;
                // }

                get_products_list({
                    ...page_info
                }).then(ret => {
                    if (ret && ret.code === 0) {
                        let list = ret.list;
                        commit('SET_PRODUCTS', list);
                        resolve(list)
                    }else {
                        resolve([])
                    }
                });

            })
        },
       
        
    }
}
export default publicStore;